A processor register is a high speed but limited capacity data storage medium, generally, embedded on a processor chip so that data stored in the register can be readily accessed by the processor. Due to the limited storage capacity of the on-chip registers, data is first stored in a slower but larger data storage medium commonly referred to as the main memory. Data is then loaded from the main memory into the processor registers, where it is manipulated by some machine instructions executed by the processor.
When a program code is executed by a processor, certain data values, represented by one or more variables, may be allocated to one or more processors registers. The allocation may be at local or global levels. If the allocation is local, the register is accessible only by the function or procedure for which the allocation is declared. If the allocation is global, the register is accessible by other functions or procedures as well. If the variables are not declared globally when a first function calls a second function, data in the locally allocated registers may have to be transferred from the registers to a memory stack and back.
The above process, commonly referred to as function switching, is associated with a lot of memory management overhead because registers with the values calculated by the first function call must transfer the respective values to the memory stack, so that the registers can be reallocated for use by the second function. Once the second function has completed execution, the registers need to be reallocated to the values used by the first function, as the control returns back to the first function for execution of the remaining instructions in the first function.
When a small number of registers are involved, the penalty associated with function switching does not significantly affect overall processing performance. In processor architectures that support large-scale register allocation, however, the corresponding penalty can impact the processor performance significantly, due to the large management overhead associated with the allocation, deallocation and reallocation of data among a large number of registers.